package cn.edu.zju.gis.disasterBE.sever.config;


import cn.edu.zju.gis.disasterBE.sever.filter.CORSFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.Collections;

/**
 * 过滤器注册
 *
 * @author SUN Katus
 * @version 1.0, 2021-07-14
 */
@Configuration
public class FilterConfig {
    /**
     * 注册跨域过滤器
     *
     * @return 跨域过滤器注册Bean
     */
    @Bean
    FilterRegistrationBean<CORSFilter> corsFilterRegistrationBean() {
        FilterRegistrationBean<CORSFilter> bean = new FilterRegistrationBean<>();
        bean.setName("corsFilter");
        bean.setFilter(new CORSFilter());
        bean.setUrlPatterns(Collections.singletonList("/*"));
        bean.setOrder(1);
        return bean;
    }

    /**
     * 注册请求包装过滤器
     *
     * @return 权限过滤器注册Bean
     */
//    @Bean
//    FilterRegistrationBean<RequestWrapperFilter> authorityFilterRegistrationBean() {
//        FilterRegistrationBean<RequestWrapperFilter> bean = new FilterRegistrationBean<>();
//        bean.setName("authorityFilter");
//        bean.setFilter(new RequestWrapperFilter());
//        bean.setUrlPatterns(Collections.singletonList("/*"));
//        bean.setOrder(2);
//        return bean;
//    }
}
